home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / processo.tar / processor.1 next >
Text File  |  1990-02-26  |  14KB  |  412 lines

  1.          HP28S PROCESSOR NOTES               Version 1
  2.  
  3.                   Copyright (C) 1989, Alonzo Gariepy
  4.  
  5. ================================================================
  6.  
  7.  
  8. The next several postings contain my notes on the HP28's CPU.  The
  9. information they hold should be sufficient for you to start machine
  10. language programming your calculator.  I make no claims about their
  11. quality or fitness for any particular purpose.    Please inform me of
  12. any errors.  I'm on the net at <uunet!microsoft!alonzo>.
  13.  
  14. Copyright (C) 1989 Alonzo M. Gariepy.
  15.  
  16. These notes are divided into four sections:
  17.  
  18.         HP28S PROCESSOR NOTES
  19.         HP28S PROCESSOR ARCHITECTURE
  20.         HP28S PROCESSOR INSTRUCTION SET
  21.         HP28S MACHINE CODE USERS GUIDE
  22.  
  23. Future notes may include:
  24.  
  25.         HP28S ASSEMBLER/DISASSEMBLER IN PROLOG
  26.         HP28S MEMORY MANAGEMENT
  27.         HP28S HARDWARE
  28.         HP28S BIBLIOGRAPHY
  29.  
  30. These notes may not be distributed for profit without the written
  31. consent of the author.
  32. ______________________________________________________________________
  33.  
  34.  
  35. I have completely reorganized and renamed the instruction set for my
  36. own purposes.  This may render these notes of no value to some people,
  37. for which I am sorry.  The new oganization and names have the following
  38. properties:
  39.  
  40. 1. One syntax for all instructions:  OPERATION.FIELD ARGS
  41.  
  42.    ARGS is zero or more register names and constants separated by commas.
  43.    This syntax simplifies reading, writing, assembly, and disassembly.
  44.  
  45. 2. Translations emphasize orthogonality (what little there is).
  46.  
  47.    The hex translations of instructions are decomposed into tables
  48.    according to the field and register(s) to be operated on.  This has
  49.    simplified the writing of a declaritive assembler/disassembler in
  50.    Prolog.  You can pick up the use of these tables very quickly.
  51.  
  52. 3. All instructions that do the same operation have the same name.
  53.  
  54.    For example, all instructions that move data into register C
  55.    have the form:
  56.             MOVE.f x,C
  57.  
  58. 4. The mnemonics are much more like those of other processors.
  59.  
  60.  
  61. Sample Program
  62. ==============
  63.  
  64. Here is a sample program called SCR.  It scrolls the display memory.
  65.  
  66.  
  67.     SCR:      ; scroll the display one pixel upwards.
  68.  
  69. 132       swap.a    a,d0     ; save D0
  70. 103       move.w    a,r3     ;  in A.
  71.  
  72. D2       clr.a     c         ; set address field of C to 0.
  73. 3122       move.p2   #22,c     ; each 1/2 of LCD is 34*2 columns (+1 on right)
  74. 27       move.1    7,p     ; point to nibble 7.
  75. 307       move.p1   7,c     ; nibble 7 gets 0111 bit mask.
  76. 10A       move.w    c,r2     ; we'll want to use these values twice.
  77. A81       clr.p     b         ; B is a flag, when set it is also a bit mask.
  78. 1B048FF    move.5    #FF840,d0     ; starting address of left columns of LCD.
  79.  
  80.     LOOP:      ; a 34 cycle loop in a 2 cycle loop: 2 * 34 * 2 = 136 columns.
  81.  
  82. 1527       move.w    @d0,a     ; read two columns (64 bits) into A.
  83. 81C       srb.w     a         ; shift them right (scroll up).
  84. 0E06       and.p     c,a     ; mask out bit shifted from first column.
  85. 1507       move.w    a,@d0     ; put back the scrolled columns.
  86.  
  87. 16F       add.a     16,d0     ; next two columns (16 nibbles hence).
  88. CE       dec.a     c         ; decrement and test the lower five nibbles of
  89. 8AE9E       brnz.a    c,LOOP     ;  C that we are using as a counter.
  90.  
  91. 90D31       brnz.p    b,FINISH     ; B==1 means we have done both sides of LCD.
  92. 1B00CFF    move.5    #FFC00,d0     ; starting address of right columns of LCD.
  93.  
  94. 11A       move.w    r2,c     ; yet another set of 34 double columns to do.
  95. A85       move.p    c,b     ; set the flag indicating last time through.
  96. 64DF       jump      LOOP
  97.  
  98.     FINISH:      ; do the remaining column and exit.
  99.  
  100. 1561       move.wp   @d0,c     ; read 32 bits (reg A didn't work).
  101. 81E       srb.w     c         ; shift column right (scroll up).
  102. 0E05       and.p     b,c     ; mask out bit shifted from first column.
  103. 1541       move.wp   c,@d0     ; put back (or maybe reg A didn't work here).
  104. 20       move.1    0,p     ; you must always restore P to 0.
  105. 113       move.w    r3,a     ; time to restore D0.
  106.  
  107. 132       move.a    a,d0     ; start dispatch.
  108. 142       move.a    @d0,a     ; where we go next.
  109. 164       add.a     5,d0     ; make D0 ready for the next guy to dispatch.
  110. 808C       jump      @a      ; bye-bye...
  111.  
  112.  
  113. ________________________________________________________________
  114.  
  115. The information in these notes comes from my own experiments,
  116. from public HP documents, and from some non-HP documents.
  117.  
  118. Foremost among the latter is the book, "Customize Your HP-28"
  119. by W.A.C. Mier-Jedrzejowicz.  This book contains a great deal
  120. of valuable information about every aspect of the HP28.  It is
  121. available from:
  122.  
  123.             SYNTHETIX
  124.             P.O. Box 1080
  125.             Berkeley, California
  126.             94701-1080, USA
  127.             (415)339-0601
  128.  
  129. Thanks to Dave Kaffine for explaining the new instructions.
  130. ________________________________________________________________
  131.  
  132.  
  133.  
  134.            HP28S PROCESSOR ARCHITECTURE           Version 1
  135.  
  136.                   Copyright (C) 1989, Alonzo Gariepy
  137.  
  138. ================================================================
  139.  
  140.  
  141. Overview
  142. ========
  143.  
  144. The HP28 (Saturn) CPU uses 64 bit data registers and 20 bit address
  145. registers.  The unit of addressibility is a four bit nibble, hence
  146. the address space of the processor is 2^20 nibbles or half a megabyte.
  147.  
  148. The HP28S address space contains 128 kilobytes of ROM at addresses
  149. #00000 to #3FFFF, and 32 kilobytes of RAM at addresses #C0000 to
  150. #CFFFF.  The RAM is aliased at addresses #D0000 to #DFFFF.  Other
  151. little chunks of the address space are used here and there for
  152. hardware control.
  153.  
  154. Most operations on data registers can be restricted to particlar
  155. ranges of nibbles, called fields.  These fields have been chosen to
  156. optimize the floating point arithmetic of the calculator.  The format
  157. for floating point numbers is a 1 nibble sign, followed by a 12
  158. nibble mantissa and 3 nibble exponent, making 16 nibbles or 64 bits
  159. in all.
  160.  
  161. The four data registers are called A, B, C, and D.  The instruction
  162. set does not allow these registers to be used interchangeably.    For
  163. example, registers A and B never interact with register D.  Memory
  164. operations are restricted to data registers A and C with the bulk of
  165. the responsibility on register C.
  166.  
  167. There is a 4 bit pointer register, called P, that is used to specify
  168. the position of a one nibble field (.P) or the length of a multi-nibble
  169. field (.WP).
  170.  
  171. The two 20 bit address registers are called D0 and D1 (go figure)
  172. and can be used interchangeably.
  173.  
  174. There are five 64 bit temporary registers called R0, R1, R2, R3, and
  175. R4.  The operations they support are restricted to moving and swapping
  176. with registers A and C.
  177.  
  178.  
  179. The HP28S system software uses some of the above registers for its
  180. own purposes.
  181.  
  182. Register B points to the end of the object heap growing up toward the
  183. stack.    Register D1 points to the end of the stack growing down
  184. toward the heap.  Register D holds the size of the free area in
  185. between.  When it reaches zero, the stack and heap have met and its
  186. time to garbage collect.  Garbage collection creates free space by
  187. discarding unused objects from the heap and compacting what is left.
  188. Memory is allocated in units of 5 nibbles.  The MEM function
  189. calculates the number of free bytes by performing garbage collection
  190. and then multiplying D by 2.5.    Register P is assumed always to be
  191. zero.  D0 is the RPL instruction pointer.
  192.  
  193. If you change any of these registers (B, D1, D, P, D0) in your
  194. machine code programs, restore their previous values before exiting.
  195.  
  196.  
  197. Fields
  198. ======
  199.  
  200. Each 64 bit register comprises 16 nibbles that can be grouped into
  201. fields for calculation and data movement.  These nibbles are numbered
  202. from right to left starting at 0; nibble 0 is the low order or least
  203. signficant nibble and nibble 15 is the high order or most significant
  204. nibble:
  205.  
  206. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  207. | 15| 14| 13| 12| 11| 10| 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
  208. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  209.  
  210. In the following diagrams, each nibble within a field is marked with
  211. its position, while those outside are blank.  The vertical bar has
  212. been removed from between the nibbles of a field.
  213.  
  214.  
  215.  
  216. Field: .P        Name: Pointer Field
  217. Start: nibble P     Size: 1 nibble        Example: RETZ.P B
  218.  
  219. +---+-    -  -  -+---+---+---+-  -  -  -+---+---+
  220. |   |           |   | P |   |          |   |   |
  221. +---+-    -  -  -+---+---+---+-  -  -  -+---+---+
  222.  
  223.  
  224.  
  225. Field: .WP        Name: Word to Pointer Field
  226. Start: nibble 0     Size: P+1 nibbles    Example: OR.WP    C,D
  227.  
  228. +---+-    -  -  -+---+---+---+-  -  -  -+---+---+
  229. |   |           |   | P    P-1        1   0 |
  230. +---+-    -  -  -+---+---+---+-  -  -  -+---+---+
  231.  
  232.  
  233.  
  234. Field: .XS        Name: Exponent Sign Field
  235. Start: nibble 2     Size: 1 nibble        Example: NOT.XS C
  236.  
  237. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  238. |   |    |   |    |   |    |   |    |   |    |   |    |   | 2 |   |    |
  239. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  240.  
  241.  
  242.  
  243. Field: .X        Name: Exponent Field
  244. Start: nibble 0     Size: 3 nibbles     Example: SUB.X    A,C
  245.  
  246. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  247. |   |    |   |    |   |    |   |    |   |    |   |    |   | 2   1   0 |
  248. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  249.  
  250.  
  251.  
  252. Field: .S        Name: Sign Field
  253. Start: nibble 15    Size: 1 nibble        Example: CLR.S    B
  254.  
  255. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  256. | 15|    |   |    |   |    |   |    |   |    |   |    |   |    |   |    |
  257. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  258.  
  259.  
  260. Field: .M        Name: Mantissa Field
  261. Start: nibble 3     Size: 12 nibbles    Example: MOVE.M B,C
  262.  
  263. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  264. |   | 14  13  12  11  10  9   8   7   6   5   4   3 |    |   |    |
  265. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  266.  
  267.  
  268.  
  269. Field: .B        Name: Byte Field
  270. Start: nibble 0     Size: 2 nibbles     Example: INC.B    C
  271.  
  272. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  273. |   |    |   |    |   |    |   |    |   |    |   |    |   |    | 1   0 |
  274. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  275.  
  276.  
  277.  
  278. Field: .W        Name: Word Field
  279. Start: nibble 0     Size: 16 nibbles    Example: SWAP.W A,R2
  280.  
  281. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  282. | 15  14  13  12  11  10  9   8   7   6   5   4   3   2   1   0 |
  283. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  284.  
  285.  
  286.  
  287. Field: .A        Name: Address Field
  288. Start: nibble 0     Size: 5 nibbles     Example: ADD.A    5,D1
  289.  
  290. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  291. |   |    |   |    |   |    |   |    |   |    |   | 4   3   2   1   0 |
  292. +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
  293.  
  294.  
  295.  
  296. Field: .n        Name: n Nibble Field
  297. Start: nibble 0     Size: n nibbles     Example: MOVE.8 @D0,A
  298.  
  299. +---+-    -  -  -+---+---+---+-  -  -  -+---+---+
  300. |   |           |   |n-1 n-2        1   0 |
  301. +---+-    -  -  -+---+---+---+-  -  -  -+---+---+
  302.  
  303.  
  304.  
  305. Field. .Pn        Name: n from Pointer Field
  306. Start: nibble P     Size: n nibbles     Example: MOVE.P3 6,C
  307.  
  308. +---+-    -  -  -+---+---+-  -  -  -+---+---+---+-  -  -    -+---+
  309. |   |           |   |P+n-1       P+1    P |   |      |   |
  310. +---+-    -  -  -+---+---+-  -  -  -+---+---+---+-  -  -    -+---+
  311.  
  312.  
  313.  
  314. Control Registers
  315. =================
  316.  
  317.  
  318. In addition to the data and address registers (A, B, C, D, R0, R1,
  319. R2, R3, R4, D0, D1, and P) the CPU also has some registers devoted to
  320. control, status, and I/O.
  321.  
  322. The control registers are 20 bits long and include the program
  323. counter (PC) and the eight level return stack (RSTK). Instructions
  324. that directly reference the PC or the return stack use all five
  325. nibbles (the .A field).
  326.  
  327.     MOVE.A    reg,PC        ; reg A or C
  328.     MOVE.A    PC,reg        ; reg A or C
  329.     MOVE.A    @reg,PC     ; reg A or C
  330.     SWAP.A    reg,PC        ; reg A or C
  331.     PUSH.A    C
  332.     POP.A    C
  333.  
  334. The PC and RSTK are indirectly modified by JUMP, BRANCH, CALL, and
  335. RETURN instructions.  One level of the return stack must be available
  336. for interrupt handling, leaving seven for program use.
  337.  
  338.  
  339. Status Registers
  340. ================
  341.  
  342.  
  343. The status registers include: the carry bit (C), the 16 bit status
  344. register (ST), and the 4 bit hardware status register (HST).  Each
  345. bit of these registers can be set or cleared individually and can be
  346. tested as part of a conditional branch or return.
  347.  
  348. The lower 12 bits (.X field) of ST can be cleared, moved, or swapped
  349. together:
  350.  
  351.     CLR.X    ST
  352.     MOVE.X    ST,C
  353.     MOVE.X    C,ST
  354.     SWAP.X    C,ST
  355.  
  356. The carry bit is set or cleared indirectly by arithmetic operations.
  357. The RETSETC and RETCLRC instructions do this directly.
  358.  
  359. The hardware status register is made up of the XM, SB, SR, and MP
  360. flags.    These can be cleared together or in any combination.  The XM
  361. bit (eXternal Module Missing) is set when the nibbles 00 are executed
  362. (the RETSETXM instruction) which happens when you jump to nonexistent
  363. memory.  SB (the Sticky Bit) is set whenever a non-zero bit is
  364. shifted out the right end of a register.  The SR bit (Service
  365. Request) is set by the SREQ instruction when there is an outstanding
  366. service requests (polling).  I do not know how the MP (Module Pulled)
  367. bit is set (perhaps when power is lost).
  368.  
  369.  
  370. I/O Registers
  371. =============
  372.  
  373. Finally, there are a 16 bit input register (IN) and a 12 bit ouput
  374. register (OUT).  The input register is used to read the keyboard, and
  375. the output register to control the beeper.
  376.  
  377.  
  378. Summary
  379. =======
  380.  
  381. Below is a table of all the registers in the CPU.  Registers that
  382. are used by the system are marked with *.  The system only uses the
  383. low 20 bits of these registers, which must be restored after use.
  384. Since R4 and RSTK are used by interrupts, you should never change
  385. the lower 20 bits of R4 nor PUSH/CALL more than seven addresses
  386. onto the return stack.
  387.  
  388.   16 nibbles       5 nibbles
  389.  Data     Temp     Addr     Ctrl     Stat     I/O    Pntr
  390. ------    ------    ------    ------    ------    -----  ------
  391.   A      R0      D0*      PC      C     IN     P*
  392.   B*      R1      D1*     RSTK*      ST ?     OUT
  393.   C      R2              HST
  394.   D*      R3
  395.       R4*
  396.  
  397.  
  398. CPU Bugs
  399. ========
  400.  
  401. The CPU has some bugs in it, instructions that do now work correctly.
  402. I have run into some, but they are difficult to accurately characterize.
  403. When NOTHING else explains your problem, suspect a bug in the processor.
  404. Two bugs that I have seen explicitly stated are:
  405.  
  406. 1.  The 818 opcodes (ADD.f x,reg and SUB.f x,reg) don't always work as
  407. advertised.  To be specific, when the field of such an instruction is
  408. XS, S, P, or WP, and a carry (or borrow) is generated out of the most
  409. significant nibble, it wraps around and affects the least significant
  410. nibble.  (Reference: Dave Kaffine).
  411.  
  412.